import { useCallback } from 'react';
/**
 * 内部使用
 * @returns
 */
export default function useDrsPermission(_ref) {
  var userInfo = _ref.userInfo;
  /**
   * 是否有权限访问
   * @fixme 状态同步疑似有问题
   */
  var canAccess = useCallback(function (permissions) {
    if (!(permissions !== null && permissions !== void 0 && permissions.length)) return true;
    return permissions.some(function (permission) {
      var _userInfo$btnList;
      return userInfo === null || userInfo === void 0 ? void 0 : (_userInfo$btnList = userInfo.btnList) === null || _userInfo$btnList === void 0 ? void 0 : _userInfo$btnList.some(function (btn) {
        return !!btn.roleBtnFlag && btn.menuCode === permission;
      });
    });
  }, [userInfo]);

  /** 获取按钮状态 */
  var getBtnInfo = useCallback(function (permission) {
    var _userInfo$btnList2;
    var found = userInfo === null || userInfo === void 0 ? void 0 : (_userInfo$btnList2 = userInfo.btnList) === null || _userInfo$btnList2 === void 0 ? void 0 : _userInfo$btnList2.find(function (btn) {
      return btn.menuCode === permission;
    });
    return found;
  }, [userInfo]);
  return {
    /** 是否有权限访问 */
    canAccess: canAccess,
    /** 获取按钮是否置灰等信息 */
    getBtnInfo: getBtnInfo
  };
}